package com.cyufeng.blog.service.mapper;

import com.cyufeng.blog.dto.SensitiveDto;
import com.cyufeng.blog.entity.Sensitive;

import java.util.ArrayList;
import java.util.List;

/**
 * 关键词检索
 *
 * @author Cyufeng
 * Data:2019.03.22
 */
public class SensitiveMapper {
    Sensitive sensitive = new Sensitive();
    SensitiveDto sensitiveDto = new SensitiveDto();

    public SensitiveDto entityTodto(Sensitive sensitive) {
        sensitiveDto.setId(sensitive.getId());
        sensitiveDto.setWord(sensitive.getWord());
        sensitiveDto.setDelTime(sensitive.getDelTime());
        sensitiveDto.setMadeTime(sensitive.getMadeTime());
        sensitiveDto.setDr(sensitive.getDr());

        //int类型转成boolean   0否 1是，是否启用
        if (sensitive.getIsEnable() == 0)
            sensitiveDto.setIsEnable(false);
        else
            sensitiveDto.setIsEnable(true);

        return sensitiveDto;
    }

    public Sensitive dtoToentity(SensitiveDto sensitiveDto) {
        sensitive.setId(sensitiveDto.getId());
        sensitive.setWord(sensitiveDto.getWord());
        sensitive.setDelTime(sensitiveDto.getDelTime());
        sensitive.setMadeTime(sensitiveDto.getMadeTime());
        sensitive.setDr(sensitiveDto.getDr());
        //boolean类型转成int   0否 1是,是否启用
        if (sensitiveDto.getIsEnable() == false)
            sensitive.setIsEnable(0);
        else
            sensitive.setIsEnable(1);

        return sensitive;
    }

    //list集合
    public List<SensitiveDto> entityTodto(List<Sensitive> accountList) {
        List<SensitiveDto> accountDtoList = new ArrayList<>();
        for (int i = 0; i < accountList.size(); i++) {
            Sensitive sensitive = accountList.get(i);
            SensitiveDto sensitiveDto = new SensitiveDto();

            sensitiveDto.setId(sensitive.getId());
            sensitiveDto.setWord(sensitive.getWord());
            sensitiveDto.setDelTime(sensitive.getDelTime());
            sensitiveDto.setMadeTime(sensitive.getMadeTime());
            sensitiveDto.setDr(sensitive.getDr());

            //int类型转成boolean   0否 1是，是否启用
            if (sensitive.getIsEnable() == 0)
                sensitiveDto.setIsEnable(false);
            else
                sensitiveDto.setIsEnable(true);
            accountDtoList.add(sensitiveDto);
        }

        return accountDtoList;
    }

    public List<Sensitive> dtoToentity(List<SensitiveDto> accountDtoList) {
        List<Sensitive> accountList = new ArrayList<>();
        for (int i = 0; i < accountList.size(); i++) {
            Sensitive sensitive = new Sensitive();
            SensitiveDto sensitiveDto = accountDtoList.get(i);

            sensitive.setId(sensitiveDto.getId());
            sensitive.setWord(sensitiveDto.getWord());
            sensitive.setDelTime(sensitiveDto.getDelTime());
            sensitive.setMadeTime(sensitiveDto.getMadeTime());
            sensitive.setDr(sensitiveDto.getDr());
            //boolean类型转成int   0否 1是,是否启用
            if (sensitiveDto.getIsEnable() == false)
                sensitive.setIsEnable(0);
            else
                sensitive.setIsEnable(1);

            accountList.add(sensitive);
        }
        return accountList;
    }
}
